﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1多态
{
    //class Animal
    //{
    //    protected string name = "";

    //    public Animal(string name)
    //    {
    //        this.name = name;
    //    }

    //    public Animal()
    //    {
    //        this.name = "无名";
    //    }

    //    protected int shoutNum = 3;

    //    public int ShoutNum
    //    {
    //        get { return shoutNum; }
    //        set { shoutNum = value; }
    //    }
    //    public virtual string Shout()
    //    {
    //        return "";
    //    }
    //}

    //class Cat : Animal
    //{
    //    public Cat() : base() { }
    //    public Cat(string name) : base(name) { }

    //    public override string Shout()
    //    {
    //        string result = "";
    //        for (int i = 0; i < shoutNum; i++)
    //        {
    //            result += "喵";               
    //        }
    //        return "我的名字叫" + name + " " + result;
    //    }
    //}

    //class Dog:Animal
    //{
    //    public Dog() : base() { }
    //    public Dog(string name) : base(name) { }

    //    public override string Shout()
    //    {
    //        string result = "";
    //        for (int i = 0; i < shoutNum; i++)
    //        {
    //            result += "汪";
    //        }
    //        return "我的名字叫" + name + " " + result;
    //    }
    //}



    class Animal
    {
        protected string name = "";

        public Animal(string name)
        {
            this.name = name;
        }

        public Animal()
        {
            this.name = "无名";
        }

        protected int shoutNum = 3;

        public int ShoutNum
        {
            get { return shoutNum; }
            set { shoutNum = value; }
        }

        public string Shout()
        {
            string result = "";
            for (int i = 0; i < shoutNum; i++)
            {
                result += GetShoutSound() + ",";
            }

            return "我的名字叫" + name + " " + result;
        }

        protected virtual string GetShoutSound()
        {
            return "";
        }
    }

    class Cat : Animal
    {
        public Cat() : base()
        {
        }

        public Cat(string name) : base(name)
        {
        }

        protected override string GetShoutSound()
        {
            return "喵";
        }
    }

    class Dog : Animal
    {
        public Dog() : base()
        {
        }

        public Dog(string name) : base(name)
        {
        }

        protected override string GetShoutSound()
        {
            return "汪";
        }
    }

    class Cattle : Animal
    {
        public Cattle() : base()
        {
        }

        public Cattle(string name) : base(name)
        {
        }

        protected override string GetShoutSound()
        {
            return "哞";
        }
    }
    class Sheep : Animal
    {
        public Sheep() : base()
        {
        }
        public Sheep(string name) : base(name)
        {
        }
        protected override string GetShoutSound()
        {
            return "咩";
        }
    }
}
